---
title: "COVID-19 unemployment-rate shock on suicide"
author: ""
date: "`r Sys.Date()`"
output:
 html_document:
    css : R_style.css
    # theme: cosmo
    highlight: haddock     # R script highlight type
    code_folding: 'hide'  # R code folding type
    toc: TRUE
    toc_depth: 3           # Heading depth 
    toc_float: true        # Heading float (横見出し)
    number_sections: true # Heading number
    df_print: paged        # head() output like notebook (good for tibble)）
    latex_engine: xelatex  # for zxjatype pacakge
    # fig_height: 4.5          # image size height default
    # fig_width: 8           # image size width default
    dev: png
classoption: xelatex,ja=standard
editor_options: 
  chunk_output_type: console
---

# Rmd Settings
```{r setup}
Sys.setenv(LANG = "en") #English
knitr::opts_chunk$set(echo = TRUE)
```

```{r}
rm(list = ls())

path <- getwd()

setwd(path)

# packages
pacman::p_load(tidyverse, plotly,readxl,scales, extrafont,PerformanceAnalytics, GGally, patchwork, ggpubr, DT, estimatr, texreg,　modelsummary)

# Font for windows and mac
if (stringr::str_detect(path, pattern="Users")){ 
  
   theme_set(theme_classic(base_size = 10, base_family = "HiraginoSans-W3"))  # For Mac OS

 } else{
  
theme_set(theme_classic(base_size = 10, base_family = "Arial"))        # For Windows
 }
```


# Contents

- WLS regression of suicide on unemployment-rate shock (unemploy_diff2)

- dynamic_DID_OLS_notrend: dynamic DID with OLS and without prefectre linear trend
- dynamic_DID_WLS_notrend: dynamic DID with WLS and without prefectre linear trend
- dynamic_DID_OLS_trend: dynamic DID with OLS and prefectre linear trend
- dynamic_DID_WLS_trend:  dynamic DID with WLS and prefectre linear trend
- dynamic_onlypost_DID_WLS_trend: dynamic DID only and with WLS and prefectre linear trend, reference periods = all the pre-COVID months

- _covar8Xcovid_months: with eight covariates interacted with month dummies

# Read functions/関数の読み込み
```{r}
source("functions.R")
```

# Read data/分析用データの読み込み

```{r}
df_analysis <- readr::read_csv("output/df_analysis.csv")
```

# Main figures in the paper 

- We firstly provide estimations and figures used in the main text.
- These chunks are copied and pasted from subsequent outcome-based result sections.
- Actual graphs and tables in the paper are generated and saved in the subsequent chunks, not the chunks in this section. But they are identical.

## WLS, with trends, Figure 3 (a) & Table C.1 (1)

- Y=suicide rate(total), without covariates

```{r}
# DID estimation
estimation_results <- dynamic_DID_WLS_trend(dataset = df_analysis, 
                    outcome_var = df_analysis$suicide_rate, 
                    treat_var = df_analysis$unemploy_shock_diff2)

texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "total_WLS_trend")

# Event study graph
graph_total_WLS_trend <- event_study_graph(data = df_estimates ,
                                          graph_title = "total_WLS_trend")

ggplotly(graph_total_WLS_trend)
```

## WLS, with trends, Figure 3 (b) & Table C.2 (1)

- Y=suicide rate(total), with covariates
- This is a baseline estimation result used in the paper.

```{r}
# DID estimation
estimation_results <- dynamic_DID_WLS_trend_covar8Xcovid_months(dataset = df_analysis, 
                    outcome_var = df_analysis$suicide_rate, 
                    treat_var = df_analysis$unemploy_shock_diff2)

texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)


# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "total_WLS_trend")
# Event study graph
graph_total_WLS_trend_covar <- event_study_graph(data = df_estimates ,
                                          graph_title = "total_WLS_trend")

ggplotly(graph_total_WLS_trend_covar)
```

## WLS, with trends, Figure 3 (c) & Table C.1 (3)

- Y=suicide rate(female), without covariates

```{r}
# DID estimation
estimation_results <- dynamic_DID_WLS_trend(dataset = df_analysis, 
                    outcome_var = df_analysis$suicide_rate_female, 
                    treat_var = df_analysis$unemploy_shock_diff2)

texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "female_WLS_trend")

# Event study graph
graph_female_WLS_trend <- event_study_graph(data = df_estimates ,
                                          graph_title = "female_WLS_trend")

ggplotly(graph_female_WLS_trend)
```

## WLS, with trends, Figure 3 (d) & Table C.2 (3)

- Y=suicide rate(female), with covariates

```{r}
# DID estimation
estimation_results <- dynamic_DID_WLS_trend_covar8Xcovid_months(dataset = df_analysis, 
                    outcome_var = df_analysis$suicide_rate_female, 
                    treat_var = df_analysis$unemploy_shock_diff2)

texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "female_WLS_trend")

# Event study graph
graph_female_WLS_trend_covar <- event_study_graph(data = df_estimates ,
                                          graph_title = "female_WLS_trend")

ggplotly(graph_female_WLS_trend_covar)
```

## WLS, with trends, Figure 3 (e) & Table C.1 (5)

- Y=suicide rate(male), without covariates

```{r}
# DID estimation
estimation_results <- dynamic_DID_WLS_trend(dataset = df_analysis, 
                    outcome_var = df_analysis$suicide_rate_male, 
                    treat_var = df_analysis$unemploy_shock_diff2)

texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "male_WLS_trend")

# Event study graph
graph_male_WLS_trend <- event_study_graph(data = df_estimates ,
                                          graph_title = "male_WLS_trend")

ggplotly(graph_male_WLS_trend)
```

## WLS, with trends, Figure 3 (f) & Table C.2 (5)

- Y=suicide rate(male), with covariates

```{r}
# DID estimation
estimation_results <- dynamic_DID_WLS_trend_covar8Xcovid_months(dataset = df_analysis, 
                    outcome_var = df_analysis$suicide_rate_male, 
                    treat_var = df_analysis$unemploy_shock_diff2)

texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "male_WLS_trend")

# Event study graph
graph_male_WLS_trend_covar <- event_study_graph(data = df_estimates ,
                                          graph_title = "male_WLS_trend")

ggplotly(graph_male_WLS_trend_covar)
```

# Y=total sucide rate/男女合計の自殺率

## OLS, no trends

```{r}
# DID estimation
estimation_results <- dynamic_DID_OLS_notrend(dataset = df_analysis, 
                    outcome_var = df_analysis$suicide_rate, 
                    treat_var = df_analysis$unemploy_shock_diff2)

#texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                 treat_var = "unemploy_shock_diff2",
                                 estimation_label = "total_OLS_notrend")

# Event study graph
graph_total_OLS_notrend <- event_study_graph(data = df_estimates,
                                          graph_title = "total_OLS_notrend")

ggplotly(graph_total_OLS_notrend)

estimates_total_OLS_notrend　<- df_estimates #for robustness check
```

## WLS, no trends

```{r}
# DID estimation
estimation_results <- dynamic_DID_WLS_notrend(dataset = df_analysis, 
                    outcome_var = df_analysis$suicide_rate, 
                    treat_var = df_analysis$unemploy_shock_diff2)

#texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "total_WLS_notrend")

# Event study graph
graph_total_WLS_notrend <- event_study_graph(data = df_estimates,
                                          graph_title = "total_WLS_notrend")

ggplotly(graph_total_WLS_notrend)

estimates_total_WLS_notrend　<- df_estimates #for robustness check
```

## OLS, with trends

```{r}
# DID estimation
estimation_results <- dynamic_DID_OLS_trend(dataset = df_analysis, 
                    outcome_var = df_analysis$suicide_rate, 
                    treat_var = df_analysis$unemploy_shock_diff2)

#texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "total_OLS_trend")

# Event study graph
graph_total_OLS_trend <- event_study_graph(data = df_estimates ,
                                          graph_title = "total_OLS_trend")

ggplotly(graph_total_OLS_trend)

estimates_total_OLS_trend　<- df_estimates #for robustness check
```

## WLS, with trends, Figure 3 (a) & Table C.1 (1)

```{r}
# DID estimation
estimation_results <- dynamic_DID_WLS_trend(dataset = df_analysis, 
                    outcome_var = df_analysis$suicide_rate, 
                    treat_var = df_analysis$unemploy_shock_diff2)

texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "total_WLS_trend")

# Event study graph
graph_total_WLS_trend <- event_study_graph(data = df_estimates ,
                                          graph_title = "total_WLS_trend")

ggplotly(graph_total_WLS_trend)

estimates_total_WLS_trend <- df_estimates #for robustness check

results_total_WLS_trend <- estimation_results # for only-post DID table
```

## WLS, with trends, post-covid-month dummies, Table C.1 (2)

```{r}
# DID estimation
estimation_results <- dynamic_onlypost_DID_WLS_trend(dataset = df_analysis, 
                    outcome_var = df_analysis$suicide_rate, 
                    treat_var = df_analysis$unemploy_shock_diff2)

texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "total_WLS_trend")

# Event study graph
graph_total_WLS_trend_onlypost <- event_study_graph(data = df_estimates ,
                                          graph_title = "total_WLS_trend")

ggplotly(graph_total_WLS_trend_onlypost)

estimates_total_WLS_trend_onlypost <- df_estimates #for robustness check

results_total_WLS_trend_onlypost <- estimation_results # for only-post DID table
```

# Y=total suicide rate/男女合計の自殺率 with covar

## OLS, no trends
```{r}
# DID estimation
estimation_results <- dynamic_DID_OLS_notrend_covar8Xcovid_months(dataset = df_analysis, 
                    outcome_var = df_analysis$suicide_rate, 
                    treat_var = df_analysis$unemploy_shock_diff2)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                 treat_var = "unemploy_shock_diff2",
                                 estimation_label = "total_OLS_notrend")
# Event study graph
graph_total_OLS_notrend_covar <- event_study_graph(data = df_estimates,
                                          graph_title = "total_OLS_notrend")

ggplotly(graph_total_OLS_notrend_covar)

estimates_total_OLS_notrend_covar <- df_estimates #for robustness check
```

## WLS, no trends

```{r}
# DID estimation
estimation_results <- dynamic_DID_WLS_notrend_covar8Xcovid_months(dataset = df_analysis, 
                    outcome_var = df_analysis$suicide_rate, 
                    treat_var = df_analysis$unemploy_shock_diff2)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "total_WLS_notrend")

# Event study graph
graph_total_WLS_notrend_covar <- event_study_graph(data = df_estimates,
                                          graph_title = "total_WLS_notrend")

ggplotly(graph_total_WLS_notrend_covar)

estimates_total_WLS_notrend_covar　<- df_estimates #for robustness check
```

## OLS, with trends

```{r}
# DID estimation
estimation_results <- dynamic_DID_OLS_trend_covar8Xcovid_months(dataset = df_analysis, 
                    outcome_var = df_analysis$suicide_rate, 
                    treat_var = df_analysis$unemploy_shock_diff2)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "total_OLS_trend")

# Event study graph
graph_total_OLS_trend_covar <- event_study_graph(data = df_estimates ,
                                          graph_title = "total_OLS_trend")

ggplotly(graph_total_OLS_trend_covar)

estimates_total_OLS_trend_covar　<- df_estimates #for robustness check

```

## WLS, with trends, Figure 3 (b) & Table C.2 (1)

- This is a baseline estimation result used in the paper.

```{r}
# DID estimation
estimation_results <- dynamic_DID_WLS_trend_covar8Xcovid_months(dataset = df_analysis, 
                    outcome_var = df_analysis$suicide_rate, 
                    treat_var = df_analysis$unemploy_shock_diff2)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "total_WLS_trend")
# Event study graph
graph_total_WLS_trend_covar <- event_study_graph(data = df_estimates ,
                                          graph_title = "total_WLS_trend")

ggplotly(graph_total_WLS_trend_covar)

estimates_total_WLS_trend_covar <- df_estimates #for robustness check

results_total_WLS_trend_covar <- estimation_results # for only-post DID table

```

## WLS, with trends, post-covid-month dummies, Table C.2 (2)

```{r}
# DID estimation
estimation_results <- dynamic_onlypost_DID_WLS_trend_covar8Xcovid_months(dataset = df_analysis, 
                    outcome_var = df_analysis$suicide_rate, 
                    treat_var = df_analysis$unemploy_shock_diff2)

texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "total_WLS_trend")
# Event study graph
graph_total_WLS_trend_covar_onlypost <- event_study_graph(data = df_estimates,
                                          graph_title = "total_WLS_trend")

ggplotly(graph_total_WLS_trend_covar_onlypost)

estimates_total_WLS_trend_covar_onlypost <- df_estimates #for robustness check

results_total_WLS_trend_covar_onlypost <- estimation_results # for only-post DID table
```

# Y=total suicide rate (YOY)/男女合計の自殺率(前年同月差）

## OLS, no trends

```{r}
# DID estimation
estimation_results <- dynamic_DID_OLS_notrend(dataset = df_analysis, 
                    outcome_var = df_analysis$yoy_suicide_rate, 
                    treat_var = df_analysis$unemploy_shock_diff2)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "yoy_total_OLS_notrend")

# Event study graph
graph_yoy_total_OLS_notrend <- event_study_graph(data = df_estimates,
                                          graph_title = "yoy_total_OLS_notrend")

ggplotly(graph_yoy_total_OLS_notrend)

estimates_yoy_total_OLS_notrend　<- df_estimates #for robustness check
```

## WLS, no trends

```{r}
# DID estimation
estimation_results <- dynamic_DID_WLS_notrend(dataset = df_analysis, 
                    outcome_var = df_analysis$yoy_suicide_rate, 
                    treat_var = df_analysis$unemploy_shock_diff2)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "yoy_total_WLS_notrend")

# Event study graph
graph_yoy_total_WLS_notrend <- event_study_graph(data = df_estimates,
                                          graph_title = "yoy_total_WLS_notrend")

ggplotly(graph_yoy_total_WLS_notrend)

estimates_yoy_total_WLS_notrend　<- df_estimates #for robustness check
```

## OLS, with trends

```{r}
# DID estimation
estimation_results <- dynamic_DID_OLS_trend(dataset = df_analysis, 
                    outcome_var = df_analysis$yoy_suicide_rate, 
                    treat_var = df_analysis$unemploy_shock_diff2)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "yoy_total_OLS_trend")

# Event study graph
graph_yoy_total_OLS_trend <- event_study_graph(data = df_estimates,
                                          graph_title = "yoy_total_OLS_trend")

ggplotly(graph_yoy_total_OLS_trend)

estimates_yoy_total_OLS_trend　<- df_estimates #for robustness check
```

## WLS, with trends

```{r}
# DID estimation
estimation_results <- dynamic_DID_WLS_trend(dataset = df_analysis, 
                    outcome_var = df_analysis$yoy_suicide_rate, 
                    treat_var = df_analysis$unemploy_shock_diff2)

texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "yoy_total_WLS_trend")

# Event study graph
graph_yoy_total_WLS_trend <- event_study_graph(data = df_estimates,
                                          graph_title = "yoy_total_WLS_trend")

ggplotly(graph_yoy_total_WLS_trend)

estimates_yoy_total_WLS_trend　<- df_estimates #for robustness check
```


# Y=total suicde rate(YOY)/男女合計の自殺率(前年同月差）with covar

## OLS, no trends

```{r}
# DID estimation
estimation_results <- dynamic_DID_OLS_notrend_covar8Xcovid_months(dataset = df_analysis, 
                    outcome_var = df_analysis$yoy_suicide_rate, 
                    treat_var = df_analysis$unemploy_shock_diff2)

#texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "yoy_total_OLS_notrend")

# Event study graph
graph_yoy_total_OLS_notrend_covar <- event_study_graph(data = df_estimates,
                                          graph_title = "yoy_total_OLS_notrend")

graph_yoy_total_OLS_notrend_covar

estimates_yoy_total_OLS_notrend_covar　<- df_estimates #for robustness check
```

## WLS, no trends

```{r}
# DID estimation
estimation_results <- dynamic_DID_WLS_notrend_covar8Xcovid_months(dataset = df_analysis, 
                    outcome_var = df_analysis$yoy_suicide_rate, 
                    treat_var = df_analysis$unemploy_shock_diff2)

#texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "yoy_total_WLS_notrend")

# Event study graph
graph_yoy_total_WLS_notrend_covar <- event_study_graph(data = df_estimates,
                                          graph_title = "yoy_total_WLS_notrend")

graph_yoy_total_WLS_notrend_covar

estimates_yoy_total_WLS_notrend_covar <- df_estimates #for robustness check
```

## OLS, with trends

```{r}
# DID estimation
estimation_results <- dynamic_DID_OLS_trend_covar8Xcovid_months(dataset = df_analysis, 
                    outcome_var = df_analysis$yoy_suicide_rate, 
                    treat_var = df_analysis$unemploy_shock_diff2)

#texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "yoy_total_OLS_trend")

# Event study graph
graph_yoy_total_OLS_trend_covar <- event_study_graph(data = df_estimates,
                                          graph_title = "yoy_total_OLS_trend")

graph_yoy_total_OLS_trend_covar

estimates_yoy_total_OLS_trend_covar <- df_estimates #for robustness check
```

## WLS, with trends

```{r}
# DID estimation
estimation_results <- dynamic_DID_WLS_trend_covar8Xcovid_months(dataset = df_analysis, 
                    outcome_var = df_analysis$yoy_suicide_rate, 
                    treat_var = df_analysis$unemploy_shock_diff2)

texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "yoy_total_WLS_trend")

# Event study graph
graph_yoy_total_WLS_trend_covar <- event_study_graph(data = df_estimates,
                                          graph_title = "yoy_total_WLS_trend")

ggplotly(graph_yoy_total_WLS_trend_covar)

estimates_yoy_total_WLS_trend_covar <- df_estimates #for robustness check
```


# Y=female suicide rate/女性の自殺率

## OLS, no trends

```{r}
# DID estimation
estimation_results <- dynamic_DID_OLS_notrend(dataset = df_analysis, 
                    outcome_var = df_analysis$suicide_rate_female, 
                    treat_var = df_analysis$unemploy_shock_diff2)

#texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                 treat_var = "unemploy_shock_diff2",
                                 estimation_label = "female_OLS_notrend")

# Event study graph
graph_female_OLS_notrend <- event_study_graph(data = df_estimates,
                                          graph_title = "female_OLS_notrend")

graph_female_OLS_notrend

estimates_female_OLS_notrend <- df_estimates #for robustness check
```

## WLS, no trends

```{r}
# DID estimation
estimation_results <- dynamic_DID_WLS_notrend(dataset = df_analysis, 
                    outcome_var = df_analysis$suicide_rate_female, 
                    treat_var = df_analysis$unemploy_shock_diff2)

#texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "female_WLS_notrend")

# Event study graph
graph_female_WLS_notrend <- event_study_graph(data = df_estimates,
                                          graph_title = "female_WLS_notrend")

ggplotly(graph_female_WLS_notrend)

estimates_female_WLS_notrend <- df_estimates #for robustness check
```

## OLS, with trends

```{r}
# DID estimation
estimation_results <- dynamic_DID_OLS_trend(dataset = df_analysis, 
                    outcome_var = df_analysis$suicide_rate_female, 
                    treat_var = df_analysis$unemploy_shock_diff2)

#texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "female_OLS_trend")

# Event study graph
graph_female_OLS_trend <- event_study_graph(data = df_estimates,
                                          graph_title = "female_OLS_trend")

ggplotly(graph_female_OLS_trend)

estimates_female_OLS_trend <- df_estimates #for robustness check
```

## WLS, with trends, Figure 3 (c) & Table C.1 (3)

```{r}
# DID estimation
estimation_results <- dynamic_DID_WLS_trend(dataset = df_analysis, 
                    outcome_var = df_analysis$suicide_rate_female, 
                    treat_var = df_analysis$unemploy_shock_diff2)

texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "female_WLS_trend")

# Event study graph
graph_female_WLS_trend <- event_study_graph(data = df_estimates ,
                                          graph_title = "female_WLS_trend")

ggplotly(graph_female_WLS_trend)

estimates_female_WLS_trend <- df_estimates #for robustness check

results_female_WLS_trend <- estimation_results # for only-post DID table

```

## WLS, with trends, post-covid-month dummies, Table C.1 (4)

```{r}
# DID estimation
estimation_results <- dynamic_onlypost_DID_WLS_trend(dataset = df_analysis, 
                    outcome_var = df_analysis$suicide_rate_female, 
                    treat_var = df_analysis$unemploy_shock_diff2)

texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "female_WLS_trend")

# Event study graph
graph_female_WLS_trend_onlypost <- event_study_graph(data = df_estimates ,
                                          graph_title = "female_WLS_trend")

ggplotly(graph_female_WLS_trend_onlypost)

estimates_female_WLS_trend_onlypost <- df_estimates #for robustness check

results_female_WLS_trend_onlypost <- estimation_results # for only-post DID table

```

# Y=female suicide rate/女性の自殺率 with covar

## OLS, no trends

```{r}
# DID estimation
estimation_results <- dynamic_DID_OLS_notrend_covar8Xcovid_months(dataset = df_analysis, 
                    outcome_var = df_analysis$suicide_rate_female, 
                    treat_var = df_analysis$unemploy_shock_diff2)

#texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                 treat_var = "unemploy_shock_diff2",
                                 estimation_label = "female_OLS_notrend")

# Event study graph
graph_female_OLS_notrend_covar <- event_study_graph(data = df_estimates,
                                          graph_title = "female_OLS_notrend")

graph_female_OLS_notrend_covar

estimates_female_OLS_notrend_covar <- df_estimates #for robustness check
```

## WLS, no trends

```{r}
# DID estimation
estimation_results <- dynamic_DID_WLS_notrend_covar8Xcovid_months(dataset = df_analysis, 
                    outcome_var = df_analysis$suicide_rate_female, 
                    treat_var = df_analysis$unemploy_shock_diff2)

#texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "female_WLS_notrend")

# Event study graph
graph_female_WLS_notrend_covar <- event_study_graph(data = df_estimates,
                                          graph_title = "female_WLS_notrend")

graph_female_WLS_notrend_covar

estimates_female_WLS_notrend_covar <- df_estimates #for robustness check
```

## OLS, with trends

```{r}
# DID estimation
estimation_results <- dynamic_DID_OLS_trend_covar8Xcovid_months(dataset = df_analysis, 
                    outcome_var = df_analysis$suicide_rate_female, 
                    treat_var = df_analysis$unemploy_shock_diff2)

#texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "female_OLS_trend")

# Event study graph
graph_female_OLS_trend_covar <- event_study_graph(data = df_estimates,
                                          graph_title = "female_OLS_trend")

graph_female_OLS_trend_covar

estimates_female_OLS_trend_covar <- df_estimates #for robustness check
```

## WLS, with trends, Figure 3 (d) & Table C.2 (3)

```{r}
# DID estimation
estimation_results <- dynamic_DID_WLS_trend_covar8Xcovid_months(dataset = df_analysis, 
                    outcome_var = df_analysis$suicide_rate_female, 
                    treat_var = df_analysis$unemploy_shock_diff2)

texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "female_WLS_trend")

# Event study graph
graph_female_WLS_trend_covar <- event_study_graph(data = df_estimates ,
                                          graph_title = "female_WLS_trend")

ggplotly(graph_female_WLS_trend_covar)

estimates_female_WLS_trend_covar <- df_estimates #for robustness check

results_female_WLS_trend_covar <- estimation_results # for only-post DID table

```

## WLS, with trends, post-covid-month dummies, Table C.2 (4)

```{r}
# DID estimation
estimation_results <- dynamic_onlypost_DID_WLS_trend_covar8Xcovid_months(dataset = df_analysis, 
                    outcome_var = df_analysis$suicide_rate_female, 
                    treat_var = df_analysis$unemploy_shock_diff2)

texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "female_WLS_trend")

# Event study graph
graph_female_WLS_trend_covar_onlypost <- event_study_graph(data = df_estimates ,
                                          graph_title = "female_WLS_trend")

ggplotly(graph_female_WLS_trend_covar_onlypost)

estimates_female_WLS_trend_covar_onlypost <- df_estimates #for robustness check

results_female_WLS_trend_covar_onlypost <- estimation_results # for only-post DID table

```

# Y=female suicide rate(YOY)/女性合計の自殺率(前年同月差）

## OLS, no trends

```{r}
# DID estimation
estimation_results <- dynamic_DID_OLS_notrend(dataset = df_analysis, 
                    outcome_var = df_analysis$yoy_suicide_rate_female, 
                    treat_var = df_analysis$unemploy_shock_diff2)

#texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "yoy_female_OLS_notrend")

# Event study graph
graph_yoy_female_OLS_notrend <- event_study_graph(data = df_estimates,
                                          graph_title = "yoy_female_OLS_notrend")

graph_yoy_female_OLS_notrend

estimates_yoy_female_OLS_notrend <- df_estimates #for robustness check

```

## WLS, no trends

```{r}
# DID estimation
estimation_results <- dynamic_DID_WLS_notrend(dataset = df_analysis, 
                    outcome_var = df_analysis$yoy_suicide_rate_female, 
                    treat_var = df_analysis$unemploy_shock_diff2)

#texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "yoy_female_WLS_notrend")

# Event study graph
graph_yoy_female_WLS_notrend <- event_study_graph(data = df_estimates,
                                          graph_title = "yoy_female_WLS_notrend")

graph_yoy_female_WLS_notrend

estimates_yoy_female_WLS_notrend <- df_estimates #for robustness check
```

## OLS, with trends

```{r}
# DID estimation
estimation_results <- dynamic_DID_OLS_trend(dataset = df_analysis, 
                    outcome_var = df_analysis$yoy_suicide_rate_female, 
                    treat_var = df_analysis$unemploy_shock_diff2)

#texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "yoy_female_OLS_trend")

# Event study graph
graph_yoy_female_OLS_trend <- event_study_graph(data = df_estimates,
                                          graph_title = "yoy_female_OLS_trend")

graph_yoy_female_OLS_trend

estimates_yoy_female_OLS_trend <- df_estimates #for robustness check
```

## WLS, with trends

```{r}
# DID estimation
estimation_results <- dynamic_DID_WLS_trend(dataset = df_analysis, 
                    outcome_var = df_analysis$yoy_suicide_rate_female, 
                    treat_var = df_analysis$unemploy_shock_diff2)

#texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "yoy_female_WLS_trend")

# Event study graph
graph_yoy_female_WLS_trend <- event_study_graph(data = df_estimates,
                                          graph_title = "yoy_female_WLS_trend")

ggplotly(graph_yoy_female_WLS_trend)

estimates_yoy_female_WLS_trend <- df_estimates #for robustness check
```



# Y=female suicide rate(YOY)/女性合計の自殺率(前年同月差）with covar

## OLS, no trends

```{r}
# DID estimation
estimation_results <- dynamic_DID_OLS_notrend_covar8Xcovid_months(dataset = df_analysis, 
                    outcome_var = df_analysis$yoy_suicide_rate_female, 
                    treat_var = df_analysis$unemploy_shock_diff2)

#texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "yoy_female_OLS_notrend")

# Event study graph
graph_yoy_female_OLS_notrend_covar <- event_study_graph(data = df_estimates,
                                          graph_title = "yoy_female_OLS_notrend")

graph_yoy_female_OLS_notrend_covar

estimates_yoy_female_OLS_notrend_covar <- df_estimates #for robustness check
```

## WLS, no trends

```{r}
# DID estimation
estimation_results <- dynamic_DID_WLS_notrend_covar8Xcovid_months(dataset = df_analysis, 
                    outcome_var = df_analysis$yoy_suicide_rate_female, 
                    treat_var = df_analysis$unemploy_shock_diff2)

#texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "yoy_female_WLS_notrend")

# Event study graph
graph_yoy_female_WLS_notrend_covar <- event_study_graph(data = df_estimates,
                                          graph_title = "yoy_female_WLS_notrend")

graph_yoy_female_WLS_notrend_covar

estimates_yoy_female_WLS_notrend_covar <- df_estimates #for robustness check
```

## OLS, with trends

```{r}
# DID estimation
estimation_results <- dynamic_DID_OLS_trend_covar8Xcovid_months(dataset = df_analysis, 
                    outcome_var = df_analysis$yoy_suicide_rate_female, 
                    treat_var = df_analysis$unemploy_shock_diff2)

#texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "yoy_female_OLS_trend")

# Event study graph
graph_yoy_female_OLS_trend_covar <- event_study_graph(data = df_estimates,
                                          graph_title = "yoy_female_OLS_trend")

graph_yoy_female_OLS_trend_covar

estimates_yoy_female_OLS_trend_covar <- df_estimates #for robustness check
```

## WLS, with trends

```{r}
# DID estimation
estimation_results <- dynamic_DID_WLS_trend_covar8Xcovid_months(dataset = df_analysis, 
                    outcome_var = df_analysis$yoy_suicide_rate_female, 
                    treat_var = df_analysis$unemploy_shock_diff2)

#texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "yoy_female_WLS_trend")

# Event study graph
graph_yoy_female_WLS_trend_covar <- event_study_graph(data = df_estimates,
                                          graph_title = "yoy_female_WLS_trend")

ggplotly(graph_yoy_female_WLS_trend_covar)

estimates_yoy_female_WLS_trend_covar <- df_estimates #for robustness check
```



# Y=male suicide rate/男性の自殺率

## OLS, no trends

```{r}
# DID estimation
estimation_results <- dynamic_DID_OLS_notrend(dataset = df_analysis, 
                    outcome_var = df_analysis$suicide_rate_male, 
                    treat_var = df_analysis$unemploy_shock_diff2)

#texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                 treat_var = "unemploy_shock_diff2",
                                 estimation_label = "male_OLS_notrend")

# Event study graph
graph_male_OLS_notrend <- event_study_graph(data = df_estimates,
                                          graph_title = "male_OLS_notrend")

graph_male_OLS_notrend

estimates_male_OLS_notrend <- df_estimates #for robustness check
```

## WLS, no trends

```{r}
# DID estimation
estimation_results <- dynamic_DID_WLS_notrend(dataset = df_analysis, 
                    outcome_var = df_analysis$suicide_rate_male, 
                    treat_var = df_analysis$unemploy_shock_diff2)

#texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "male_WLS_notrend")

# Event study graph
graph_male_WLS_notrend <- event_study_graph(data = df_estimates,
                                          graph_title = "male_WLS_notrend")

graph_male_WLS_notrend

estimates_male_WLS_notrend <- df_estimates #for robustness check
```

## OLS, with trends

```{r}
# DID estimation
estimation_results <- dynamic_DID_OLS_trend(dataset = df_analysis, 
                    outcome_var = df_analysis$suicide_rate_male, 
                    treat_var = df_analysis$unemploy_shock_diff2)

#texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "male_OLS_trend")

# Event study graph
graph_male_OLS_trend <- event_study_graph(data = df_estimates ,
                                          graph_title = "male_OLS_trend")

graph_male_OLS_trend

estimates_male_OLS_trend <- df_estimates #for robustness check
```

## WLS, with trends, Figure 3 (e) & Table C.1 (5)

```{r}
# DID estimation
estimation_results <- dynamic_DID_WLS_trend(dataset = df_analysis, 
                    outcome_var = df_analysis$suicide_rate_male, 
                    treat_var = df_analysis$unemploy_shock_diff2)

texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "male_WLS_trend")

# Event study graph
graph_male_WLS_trend <- event_study_graph(data = df_estimates ,
                                          graph_title = "male_WLS_trend")

ggplotly(graph_male_WLS_trend)

estimates_male_WLS_trend <- df_estimates #for robustness check

results_male_WLS_trend <- estimation_results # for only-post DID table

```

## WLS, with trends, post-covid-month dummies, Table C.1 (6)

```{r}
# DID estimation
estimation_results <- dynamic_onlypost_DID_WLS_trend(dataset = df_analysis, 
                    outcome_var = df_analysis$suicide_rate_male, 
                    treat_var = df_analysis$unemploy_shock_diff2)

texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "male_WLS_trend")

# Event study graph
graph_male_WLS_trend_onlypost <- event_study_graph(data = df_estimates ,
                                          graph_title = "male_WLS_trend")

ggplotly(graph_male_WLS_trend_onlypost)

estimates_male_WLS_trend_onlypost <- df_estimates #for robustness check

results_male_WLS_trend_onlypost <- estimation_results # for only-post DID table

```


# Y=male suicide rate/男性の自殺率 with covar

## OLS, no trends

```{r}
# DID estimation
estimation_results <- dynamic_DID_OLS_notrend_covar8Xcovid_months(dataset = df_analysis, 
                    outcome_var = df_analysis$suicide_rate_male, 
                    treat_var = df_analysis$unemploy_shock_diff2)

#texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                 treat_var = "unemploy_shock_diff2",
                                 estimation_label = "male_OLS_notrend")

# Event study graph
graph_male_OLS_notrend_covar <- event_study_graph(data = df_estimates,
                                          graph_title = "male_OLS_notrend")

graph_male_OLS_notrend_covar

estimates_male_OLS_notrend_covar <- df_estimates #for robustness check
```

## WLS, no trends

```{r}
# DID estimation
estimation_results <- dynamic_DID_WLS_notrend_covar8Xcovid_months(dataset = df_analysis, 
                    outcome_var = df_analysis$suicide_rate_male, 
                    treat_var = df_analysis$unemploy_shock_diff2)

#texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "male_WLS_notrend")

# Event study graph
graph_male_WLS_notrend_covar <- event_study_graph(data = df_estimates,
                                          graph_title = "male_WLS_notrend")

graph_male_WLS_notrend_covar

estimates_male_WLS_notrend_covar <- df_estimates #for robustness check
```

## OLS, with trends

```{r}
# DID estimation
estimation_results <- dynamic_DID_OLS_trend_covar8Xcovid_months(dataset = df_analysis, 
                    outcome_var = df_analysis$suicide_rate_male, 
                    treat_var = df_analysis$unemploy_shock_diff2)

#texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "male_OLS_trend")

# Event study graph
graph_male_OLS_trend_covar <- event_study_graph(data = df_estimates ,
                                          graph_title = "male_OLS_trend")

graph_male_OLS_trend_covar

estimates_male_OLS_trend_covar <- df_estimates #for robustness check
```

## WLS, with trends, Figure 3 (f) & Table C.2 (5)

```{r}
# DID estimation
estimation_results <- dynamic_DID_WLS_trend_covar8Xcovid_months(dataset = df_analysis, 
                    outcome_var = df_analysis$suicide_rate_male, 
                    treat_var = df_analysis$unemploy_shock_diff2)

texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "male_WLS_trend")

# Event study graph
graph_male_WLS_trend_covar <- event_study_graph(data = df_estimates ,
                                          graph_title = "male_WLS_trend")

ggplotly(graph_male_WLS_trend_covar)

estimates_male_WLS_trend_covar <- df_estimates #for robustness check

results_male_WLS_trend_covar <- estimation_results # for only-post DID table

```

## WLS, with trends, post-covid-month dummies,Table C.2 (6)

```{r}
# DID estimation
estimation_results <- dynamic_onlypost_DID_WLS_trend_covar8Xcovid_months(dataset = df_analysis, 
                    outcome_var = df_analysis$suicide_rate_male, 
                    treat_var = df_analysis$unemploy_shock_diff2)

texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "male_WLS_trend")

# Event study graph
graph_male_WLS_trend_covar_onlypost <- event_study_graph(data = df_estimates ,
                                          graph_title = "male_WLS_trend")

ggplotly(graph_male_WLS_trend_covar_onlypost)

estimates_male_WLS_trend_covar_onlypost <- df_estimates #for robustness check

results_male_WLS_trend_covar_onlypost <- estimation_results # for only-post DID table

```


# Y=male suicide rate(YOY)/男性計の自殺率(前年同月差）

## OLS, no trends

```{r}
# DID estimation
estimation_results <- dynamic_DID_OLS_notrend(dataset = df_analysis, 
                    outcome_var = df_analysis$yoy_suicide_rate_male, 
                    treat_var = df_analysis$unemploy_shock_diff2)

#texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "yoy_male_OLS_notrend")

# Event study graph
graph_yoy_male_OLS_notrend <- event_study_graph(data = df_estimates,
                                          graph_title = "yoy_male_OLS_notrend")

graph_yoy_male_OLS_notrend

estimates_yoy_male_OLS_notrend <- df_estimates #for robustness check
```

## WLS, no trends

```{r}
# DID estimation
estimation_results <- dynamic_DID_WLS_notrend(dataset = df_analysis, 
                    outcome_var = df_analysis$yoy_suicide_rate_male, 
                    treat_var = df_analysis$unemploy_shock_diff2)

#texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "yoy_male_WLS_notrend")

# Event study graph
graph_yoy_male_WLS_notrend <- event_study_graph(data = df_estimates,
                                          graph_title = "yoy_male_WLS_notrend")

graph_yoy_male_WLS_notrend

estimates_yoy_male_WLS_notrend  <- df_estimates #for robustness check
```

## OLS, with trends

```{r}
# DID estimation
estimation_results <- dynamic_DID_OLS_trend(dataset = df_analysis, 
                    outcome_var = df_analysis$yoy_suicide_rate_male, 
                    treat_var = df_analysis$unemploy_shock_diff2)

#texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "yoy_male_OLS_trend")

# Event study graph
graph_yoy_male_OLS_trend <- event_study_graph(data = df_estimates,
                                          graph_title = "yoy_male_OLS_trend")

graph_yoy_male_OLS_trend

estimates_yoy_male_OLS_trend  <- df_estimates #for robustness check
```

## WLS, with trends

```{r}
# DID estimation
estimation_results <- dynamic_DID_WLS_trend(dataset = df_analysis, 
                    outcome_var = df_analysis$yoy_suicide_rate_male, 
                    treat_var = df_analysis$unemploy_shock_diff2)

#texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "yoy_male_WLS_trend")

# Event study graph
graph_yoy_male_WLS_trend <- event_study_graph(data = df_estimates,
                                          graph_title = "yoy_male_WLS_trend")

ggplotly(graph_yoy_male_WLS_trend)

estimates_yoy_male_WLS_trend  <- df_estimates #for robustness check
```


# Y=male suicide rate(YOY)/男性計の自殺率(前年同月差）with covar

## OLS, no trends

```{r}
# DID estimation
estimation_results <- dynamic_DID_OLS_notrend_covar8Xcovid_months(dataset = df_analysis, 
                    outcome_var = df_analysis$yoy_suicide_rate_male, 
                    treat_var = df_analysis$unemploy_shock_diff2)

#texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "yoy_male_OLS_notrend")

# Event study graph
graph_yoy_male_OLS_notrend_covar <- event_study_graph(data = df_estimates,
                                          graph_title = "yoy_male_OLS_notrend")

graph_yoy_male_OLS_notrend_covar

estimates_yoy_male_OLS_notrend_covar  <- df_estimates #for robustness check
```

## WLS, no trends

```{r}
# DID estimation
estimation_results <- dynamic_DID_WLS_notrend_covar8Xcovid_months(dataset = df_analysis, 
                    outcome_var = df_analysis$yoy_suicide_rate_male, 
                    treat_var = df_analysis$unemploy_shock_diff2)

#texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "yoy_male_WLS_notrend")

# Event study graph
graph_yoy_male_WLS_notrend_covar <- event_study_graph(data = df_estimates,
                                          graph_title = "yoy_male_WLS_notrend")

graph_yoy_male_WLS_notrend_covar

estimates_yoy_male_WLS_notrend_covar  <- df_estimates #for robustness check
```

## OLS, with trends

```{r}
# DID estimation
estimation_results <- dynamic_DID_OLS_trend_covar8Xcovid_months(dataset = df_analysis, 
                    outcome_var = df_analysis$yoy_suicide_rate_male, 
                    treat_var = df_analysis$unemploy_shock_diff2)

#texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "yoy_male_OLS_trend")

# Event study graph
graph_yoy_male_OLS_trend_covar <- event_study_graph(data = df_estimates,
                                          graph_title = "yoy_male_OLS_trend")

graph_yoy_male_OLS_trend_covar

estimates_yoy_male_OLS_trend_covar  <- df_estimates #for robustness check
```

## WLS, with trends

```{r}
# DID estimation
estimation_results <- dynamic_DID_WLS_trend_covar8Xcovid_months(dataset = df_analysis, 
                    outcome_var = df_analysis$yoy_suicide_rate_male, 
                    treat_var = df_analysis$unemploy_shock_diff2)

#texreg::screenreg(l = estimation_results , include.ci = FALSE, digits=3)

# DID estimates and 90% CI
df_estimates <- DID_coefficients_main(DID_results = estimation_results, 
                                         treat_var = "unemploy_shock_diff2",
                                 estimation_label = "yoy_male_WLS_trend")

# Event study graph
graph_yoy_male_WLS_trend_covar <- event_study_graph(data = df_estimates,
                                          graph_title = "yoy_male_WLS_trend")

ggplotly(graph_yoy_male_WLS_trend_covar)

estimates_yoy_male_WLS_trend_covar  <- df_estimates #for robustness check
```

## GGplotly

```{r}
ggplotly(graph_total_WLS_trend)
ggplotly(graph_total_WLS_trend_covar)
ggplotly(graph_female_WLS_trend)
ggplotly(graph_female_WLS_trend_covar)
ggplotly(graph_male_WLS_trend)
ggplotly(graph_male_WLS_trend_covar)

```

# Merge outcome results/アウトカム結果の結合
## Y=total suicide rate/男女合計の自殺率

```{r}
#merge and label estimates data
estimates_total_bind <- dplyr::bind_rows(estimates_total_OLS_notrend, 
                                         estimates_total_WLS_notrend, 
                                         estimates_total_OLS_trend,
                                         estimates_total_WLS_trend)

#change labels and reorder labels
estimates_total_bind <- estimates_labeling_main(estimates_total_bind)

# Display results
DT::datatable(estimates_total_bind) %>%
   DT::formatRound(columns = c("estimate", "ci_lower", "ci_upper"), digits=3)

#graph
graph_total_bind <- event_study_graph_bind_main(data = estimates_total_bind, 
                                             graph_title = "(a) Total suicide rate")

ggplotly(graph_total_bind)
#ggplotly(graph_total_bind)
```

## Y=total suicide rate/男女合計の自殺率 with covar

```{r}
#merge and label estimates data
estimates_total_bind <- dplyr::bind_rows(estimates_total_OLS_notrend_covar, 
                                         estimates_total_WLS_notrend_covar, 
                                         estimates_total_OLS_trend_covar,
                                         estimates_total_WLS_trend_covar)

#change labels and reorder labels
estimates_total_bind <- estimates_labeling_main(estimates_total_bind)

# Display results
DT::datatable(estimates_total_bind) %>%
   DT::formatRound(columns = c("estimate", "ci_lower", "ci_upper"), digits=3)

#graph
graph_total_bind_covar <- event_study_graph_bind_main(data = estimates_total_bind, 
                                             graph_title = "(a) Total suicide rate")

ggplotly(graph_total_bind_covar)
```

## Y=total suicide rate(YOY)/男女合計の自殺率(対前年同期差)

```{r}
#merge and label estimates data
estimates_yoy_total_bind <- dplyr::bind_rows(estimates_yoy_total_OLS_notrend, 
                                             estimates_yoy_total_WLS_notrend, 
                                             estimates_yoy_total_OLS_trend,
                                             estimates_yoy_total_WLS_trend)

#change labels and reorder labels
estimates_yoy_total_bind <- estimates_labeling_main(estimates_yoy_total_bind)

# display results
DT::datatable(estimates_yoy_total_bind) %>%
   DT::formatRound(columns = c("estimate", "ci_lower", "ci_upper"), digits=3)

#graph
graph_yoy_total_bind <- event_study_graph_bind_main(data = estimates_yoy_total_bind, 
                                             graph_title = "(b) Total suicide rate (year-on-year)")

ggplotly(graph_yoy_total_bind)
```

## Y=total suicide rate(YOY)/男女合計の自殺率(対前年同期差) with covar

```{r}
#merge and label estimates data
estimates_yoy_total_bind <- dplyr::bind_rows(estimates_yoy_total_OLS_notrend_covar, 
                                             estimates_yoy_total_WLS_notrend_covar, 
                                             estimates_yoy_total_OLS_trend_covar,
                                             estimates_yoy_total_WLS_trend_covar)

#change labels and reorder labels
estimates_yoy_total_bind <- estimates_labeling_main(estimates_yoy_total_bind)

# display results
DT::datatable(estimates_yoy_total_bind) %>%
   DT::formatRound(columns = c("estimate", "ci_lower", "ci_upper"), digits=3)

#graph
graph_yoy_total_bind_covar <- event_study_graph_bind_main(data = estimates_yoy_total_bind, 
                                             graph_title = "(b) Total suicide rate (year-on-year)")

ggplotly(graph_yoy_total_bind_covar)

```



## Y=female suicide rate/女性の自殺率

```{r}
#merge and label estimates data
estimates_female_bind <- dplyr::bind_rows(estimates_female_OLS_notrend, 
                                          estimates_female_WLS_notrend, 
                                          estimates_female_OLS_trend,
                                          estimates_female_WLS_trend)

#change labels and reorder labels
estimates_female_bind <- estimates_labeling_main(estimates_female_bind)

# display results
DT::datatable(estimates_female_bind) %>%
   DT::formatRound(columns = c("estimate", "ci_lower", "ci_upper"), digits=3)

#graph
graph_female_bind <- event_study_graph_bind_main(data = estimates_female_bind, 
                                             graph_title = "(c) Female suicide rate")

ggplotly(graph_female_bind)

```

## Y=female suicide rate/女性の自殺率 with covar

```{r}
#merge and label estimates data
estimates_female_bind <- dplyr::bind_rows(estimates_female_OLS_notrend_covar, 
                                          estimates_female_WLS_notrend_covar, 
                                          estimates_female_OLS_trend_covar,
                                          estimates_female_WLS_trend_covar)

#change labels and reorder labels
estimates_female_bind <- estimates_labeling_main(estimates_female_bind)

# display results
DT::datatable(estimates_female_bind) %>%
   DT::formatRound(columns = c("estimate", "ci_lower", "ci_upper"), digits=3)

#graph
graph_female_bind_covar <- event_study_graph_bind_main(data = estimates_female_bind, 
                                             graph_title = "(c) Female suicide rate")

ggplotly(graph_female_bind_covar)

```


## Y=female suicide rate(YOY)/女性の自殺率(対前年同期差)

```{r}
#merge and label estimates data
estimates_yoy_female_bind <- dplyr::bind_rows(estimates_yoy_female_OLS_notrend, 
                                              estimates_yoy_female_WLS_notrend, 
                                              estimates_yoy_female_OLS_trend,
                                              estimates_yoy_female_WLS_trend)

#change labels and reorder labels
estimates_yoy_female_bind <- estimates_labeling_main(estimates_yoy_female_bind)


# display results
DT::datatable(estimates_yoy_female_bind) %>%
   DT::formatRound(columns = c("estimate", "ci_lower", "ci_upper"), digits=3)

#graph
graph_yoy_female_bind <- event_study_graph_bind_main(data = estimates_yoy_female_bind, 
                                             graph_title = "(d) Female suicide rate (year-on-year)")

ggplotly(graph_yoy_female_bind)

```

## Y=female suicide rate(YOY)/女性の自殺率(対前年同期差) with covar

```{r}
#merge and label estimates data
estimates_yoy_female_bind <- dplyr::bind_rows(estimates_yoy_female_OLS_notrend_covar, 
                                              estimates_yoy_female_WLS_notrend_covar, 
                                              estimates_yoy_female_OLS_trend_covar,
                                              estimates_yoy_female_WLS_trend_covar)

#change labels and reorder labels
estimates_yoy_female_bind <- estimates_labeling_main(estimates_yoy_female_bind)


# display results
DT::datatable(estimates_yoy_female_bind) %>%
   DT::formatRound(columns = c("estimate", "ci_lower", "ci_upper"), digits=3)

#graph
graph_yoy_female_bind_covar <- event_study_graph_bind_main(data = estimates_yoy_female_bind, 
                                             graph_title = "(d) Female suicide rate (year-on-year)")

ggplotly(graph_yoy_female_bind_covar)

```

## Y=male suicide rate/男性の自殺率

```{r}
#merge and label estimates data
estimates_male_bind <- dplyr::bind_rows(estimates_male_OLS_notrend, 
                                        estimates_male_WLS_notrend, 
                                        estimates_male_OLS_trend,
                                        estimates_male_WLS_trend)

#change labels and reorder labels
estimates_male_bind <- estimates_labeling_main(estimates_male_bind)


# display results
DT::datatable(estimates_male_bind) %>%
   DT::formatRound(columns = c("estimate", "ci_lower", "ci_upper"), digits=3)

#graph
graph_male_bind <- event_study_graph_bind_main(data = estimates_male_bind, 
                                             graph_title = "(e) Male Suicide rate")

ggplotly(graph_male_bind)

```

## Y=male suicide rate/男性の自殺率 with covar

```{r}
#merge and label estimates data
estimates_male_bind <- dplyr::bind_rows(estimates_male_OLS_notrend_covar, 
                                        estimates_male_WLS_notrend_covar, 
                                        estimates_male_OLS_trend_covar,
                                        estimates_male_WLS_trend_covar)

#change labels and reorder labels
estimates_male_bind <- estimates_labeling_main(estimates_male_bind)


# display results
DT::datatable(estimates_male_bind) %>%
   DT::formatRound(columns = c("estimate", "ci_lower", "ci_upper"), digits=3)

#graph
graph_male_bind_covar <- event_study_graph_bind_main(data = estimates_male_bind, 
                                             graph_title = "(e) Male Suicide rate")

ggplotly(graph_male_bind_covar)

```


## Y=male suicide rate(YOY)/男性の自殺率(対前年同期差)

```{r}
#merge and label estimates data
estimates_yoy_male_bind <- dplyr::bind_rows(estimates_yoy_male_OLS_notrend, 
                                            estimates_yoy_male_WLS_notrend, 
                                            estimates_yoy_male_OLS_trend,
                                            estimates_yoy_male_WLS_trend)

#change labels and reorder labels
estimates_yoy_male_bind <- estimates_labeling_main(estimates_yoy_male_bind)


# display results
DT::datatable(estimates_yoy_male_bind) %>%
   DT::formatRound(columns = c("estimate", "ci_lower", "ci_upper"), digits=3)

#graph
graph_yoy_male_bind <- event_study_graph_bind_main(data = estimates_yoy_male_bind, 
                                             graph_title = "(f) Male Suicide rate (year-on-year)")

ggplotly(graph_yoy_male_bind)

```

## Y=male suicide rate(YOY)/男性の自殺率(対前年同期差) with covar

```{r}
#merge and label estimates data
estimates_yoy_male_bind <- dplyr::bind_rows(estimates_yoy_male_OLS_notrend_covar, 
                                            estimates_yoy_male_WLS_notrend_covar, 
                                            estimates_yoy_male_OLS_trend_covar,
                                            estimates_yoy_male_WLS_trend_covar)

#change labels and reorder labels
estimates_yoy_male_bind <- estimates_labeling_main(estimates_yoy_male_bind)


# display results
DT::datatable(estimates_yoy_male_bind) %>%
   DT::formatRound(columns = c("estimate", "ci_lower", "ci_upper"), digits=3)

#graph
graph_yoy_male_bind_covar <- event_study_graph_bind_main(data = estimates_yoy_male_bind, 
                                             graph_title = "(f) Male Suicide rate (year-on-year)")

ggplotly(graph_yoy_male_bind_covar)

```

# Merge graphs/グラフ統合

# Extract legend/legend取り出し

```{r}
#Legendの表示
graph_for_legend  <-　graph_total_bind +
 theme(legend.position = 'bottom', # Adjust x axis label
       legend.title = element_text(colour = "black", size = 20),
       legend.text = element_text(color = "black", size = 20))
graph_for_legend  

#extract legend
legend_model_types <- ggpubr::get_legend(graph_for_legend)
legend_model_types <- ggpubr::as_ggplot(legend_model_types)
legend_model_types


#２行Legendの表示
graph_for_legend_2row  <-　graph_total_bind +
 theme(legend.position = 'bottom', # Adjust x axis label
       legend.title = element_text(colour = "black", size = 20),
       legend.text = element_text(color = "black", size = 20))+
  guides(color = guide_legend(nrow = 2, byrow = TRUE)) #legendを二行に変更　2021Sep7 Waki 
graph_for_legend_2row  

#extract legend
legend_2row_model_types <- ggpubr::get_legend(graph_for_legend_2row)
legend_2row_model_types <- ggpubr::as_ggplot(legend_2row_model_types)
legend_2row_model_types


```

## Merge/統合

グラフを統合して論文用に保存。
### graph size

```{r}
dpi_num <- 100
width_num <- 15
height_num <- 20
```

### WLS with linear trends
```{r, fig.width = 10, fig.height = 15}

#graph setting
ymin <- - 0.75
ymax <- 1.1

ymin_num <- - 0.5
ymax_num  <- 1
interval <- 0.5

graph_total_WLS_trend <- graph_total_WLS_trend + 
  labs(title = "(a) Total") + 
    scale_y_continuous(limit = c(ymin, ymax), breaks=seq(ymin_num, ymax_num, interval))

graph_total_WLS_trend_covar <- graph_total_WLS_trend_covar + 
  labs(title = "(b) Total, with covaraites") + 
    scale_y_continuous(limit = c(ymin, ymax), breaks=seq(ymin_num, ymax_num, interval))

graph_female_WLS_trend <- graph_female_WLS_trend + 
  labs(title = "(c) Female")+ 
    scale_y_continuous(limit = c(ymin, ymax), breaks=seq(ymin_num, ymax_num, interval))

graph_female_WLS_trend_covar <- graph_female_WLS_trend_covar + 
  labs(title = "(d) Female, with covaraites") + 
    scale_y_continuous(limit = c(ymin, ymax), breaks=seq(ymin_num, ymax_num, interval))

graph_male_WLS_trend <- graph_male_WLS_trend + 
  labs(title = "(e) Male")+ 
    scale_y_continuous(limit = c(ymin, ymax), breaks=seq(ymin_num, ymax_num, interval))

graph_male_WLS_trend_covar <- graph_male_WLS_trend_covar + 
  labs(title = "(f) Male, with covaraites") + 
    scale_y_continuous(limit = c(ymin, ymax), breaks=seq(ymin_num, ymax_num, interval))

graph <- (graph_total_WLS_trend | graph_total_WLS_trend_covar) / 
  (graph_female_WLS_trend | graph_female_WLS_trend_covar) / 
  (graph_male_WLS_trend | graph_male_WLS_trend_covar)　/
   plot_layout(heights = c(2, 2, 2))


graph

#保存
ggsave(file = "output/graph_unemploy_diff2_on_suicide_WLStrends.pdf", plot = graph, 
       dpi = dpi_num, width = width_num, height = height_num)     
```

### WLS with linear trends (YOY)
```{r, fig.width = 10, fig.height = 15}


ymin <- - 0.75
ymax <- 1.1

ymin_num <- - 0.5
ymax_num  <- 1
interval <- 0.5

graph_yoy_total_WLS_trend <- graph_yoy_total_WLS_trend + 
  labs(title = "(a) Total") + 
    scale_y_continuous(limit = c(ymin, ymax), breaks=seq(ymin_num, ymax_num, interval))

graph_yoy_total_WLS_trend_covar <- graph_yoy_total_WLS_trend_covar + 
  labs(title = "(b) Total, with covaraites") + 
    scale_y_continuous(limit = c(ymin, ymax), breaks=seq(ymin_num, ymax_num, interval))

graph_yoy_female_WLS_trend <- graph_yoy_female_WLS_trend + 
  labs(title = "(c) Female")+ 
    scale_y_continuous(limit = c(ymin, ymax), breaks=seq(ymin_num, ymax_num, interval))

graph_yoy_female_WLS_trend_covar <- graph_yoy_female_WLS_trend_covar + 
  labs(title = "(d) Female, with covaraites") + 
    scale_y_continuous(limit = c(ymin, ymax), breaks=seq(ymin_num, ymax_num, interval))

graph_yoy_male_WLS_trend <- graph_yoy_male_WLS_trend + 
  labs(title = "(e) Male ")+ 
    scale_y_continuous(limit = c(ymin, ymax), breaks=seq(ymin_num, ymax_num, interval))

graph_yoy_male_WLS_trend_covar <- graph_yoy_male_WLS_trend_covar + 
  labs(title = "(f) Male, with covaraites") + 
    scale_y_continuous(limit = c(ymin, ymax), breaks=seq(ymin_num, ymax_num, interval))

graph <- (graph_yoy_total_WLS_trend | graph_yoy_total_WLS_trend_covar) / 
  (graph_yoy_female_WLS_trend | graph_yoy_female_WLS_trend_covar) / 
  (graph_yoy_male_WLS_trend | graph_yoy_male_WLS_trend_covar) /
  legend_model_types +
  plot_layout(heights = c(2, 2, 2, 0.5))
graph

#保存
ggsave(file = "output/graph_unemploy_diff2_on_yoy_suicide_WLStrends.pdf", plot = graph, 
       dpi = dpi_num, width = width_num, height = height_num)     
```

### Robustness check
```{r, fig.width = 10, fig.height = 15}

ymin <- - 1.5
ymax <- 1.6

ymin_num <- - 1.5
ymax_num  <- 1.5
interval <- 0.5


graph_total_bind <- graph_total_bind + 
  labs(title = "(a) Total") + 
    scale_y_continuous(limit = c(ymin, ymax), breaks=seq(ymin_num, ymax_num, interval))

graph_total_bind_covar <- graph_total_bind_covar + 
  labs(title = "(b) Total, with covaraites") + 
    scale_y_continuous(limit = c(ymin, ymax), breaks=seq(ymin_num, ymax_num, interval))


graph_female_bind <- graph_female_bind + 
  labs(title = "(c) Female")+ 
    scale_y_continuous(limit = c(ymin, ymax), breaks=seq(ymin_num, ymax_num, interval))

graph_female_bind_covar <- graph_female_bind_covar + 
  labs(title = "(d) Female, with covaraites") + 
    scale_y_continuous(limit = c(ymin, ymax), breaks=seq(ymin_num, ymax_num, interval))

graph_male_bind <- graph_male_bind + 
  labs(title = "(e) Male")+ 
    scale_y_continuous(limit = c(ymin, ymax), breaks=seq(ymin_num, ymax_num, interval))

graph_male_bind_covar <- graph_male_bind_covar + 
  labs(title = "(f) Male, with covaraites") + 
    scale_y_continuous(limit = c(ymin, ymax), breaks=seq(ymin_num, ymax_num, interval))

graph <- (graph_total_bind | graph_total_bind_covar) / 
  (graph_female_bind| graph_female_bind_covar) / 
  (graph_male_bind| graph_male_bind_covar) /
  legend_model_types +
  plot_layout(heights = c(2, 2, 2, 0.5))

graph

#保存

ggsave(file = "output/graph_unemploy_diff2_on_suicide_robust.pdf", plot = graph, 
       dpi = dpi_num, width = width_num, height = height_num)     
```

### Robustness check (YOY) 
```{r, fig.width = 10, fig.height = 15}
graph_yoy_total_bind <- graph_yoy_total_bind + 
  labs(title = "(a) Total") + 
    scale_y_continuous(limit = c(ymin, ymax), breaks=seq(ymin_num, ymax_num, interval))

graph_yoy_total_bind_covar <- graph_yoy_total_bind_covar + 
  labs(title = "(b) Total, with covaraites") + 
    scale_y_continuous(limit = c(ymin, ymax), breaks=seq(ymin_num, ymax_num, interval))

graph_yoy_female_bind <- graph_yoy_female_bind + 
  labs(title = "(c) Female")+ 
    scale_y_continuous(limit = c(ymin, ymax), breaks=seq(ymin_num, ymax_num, interval))

graph_yoy_female_bind_covar <- graph_yoy_female_bind_covar + 
  labs(title = "(d) Female, with covaraites") + 
    scale_y_continuous(limit = c(ymin, ymax), breaks=seq(ymin_num, ymax_num, interval))

graph_yoy_male_bind <- graph_yoy_male_bind + 
  labs(title = "(e) Male")+ 
    scale_y_continuous(limit = c(ymin, ymax), breaks=seq(ymin_num, ymax_num, interval))

graph_yoy_male_bind_covar <- graph_yoy_male_bind_covar + 
  labs(title = "(f) Male, with covaraites") + 
    scale_y_continuous(limit = c(ymin, ymax), breaks=seq(ymin_num, ymax_num, interval))

graph <- (graph_yoy_total_bind | graph_yoy_total_bind_covar) / 
  (graph_yoy_female_bind| graph_yoy_female_bind_covar) / 
  (graph_yoy_male_bind| graph_yoy_male_bind_covar) /
  legend_model_types +
  plot_layout(heights = c(2, 2, 2, 0.5))

graph

#保存

ggsave(file = "output/graph_unemploy_diff2_on_yoy_suicide_robust.pdf", plot = graph, 
       dpi = dpi_num, width = width_num, height = height_num)     
```


# Regression table/回帰結果表 without covar

```{r DID_unemploy_on_suicide}
options("modelsummary_format_numeric_latex" = "plain")

# 列の選択 column order

# 男女合計、女性、男性、YOYのみ, monthlyhのみ

rows_MONTH <- tribble(~name, ~"(1)", ~"(2)", ~"(3)", ~"(4)", ~"(5)", ~"(6)", 
"Ref. month", "\\footnotesize{Jan.2020}", "\\footnotesize{$\\leq$Jan.2020}",  "\\footnotesize{Jan.2020}", "\\footnotesize{$\\leq$Jan.2020}","\\footnotesize{Jan.2020}", "\\footnotesize{$\\leq$Jan.2020}")

## results list
table_results_MONTH <- list()
table_results_MONTH[["(1)"]] <- results_total_WLS_trend
table_results_MONTH[["(2)"]] <- results_total_WLS_trend_onlypost
table_results_MONTH[["(3)"]] <- results_female_WLS_trend
table_results_MONTH[["(4)"]] <- results_female_WLS_trend_onlypost
table_results_MONTH[["(5)"]] <- results_male_WLS_trend
table_results_MONTH[["(6)"]] <- results_male_WLS_trend_onlypost

## HTML table
estimates_table_MONTH(df = table_results_MONTH,
                      rows = rows_MONTH,
                      title_words = "Suicide",
                      gof = gm,
                      output_style = "html") %>%
    kableExtra::add_header_above(c(" " = 1, "Total" = 2, "Female" = 2, "Male" = 2))

## Latex table
estimates_table_MONTH(df = table_results_MONTH,
                      rows = rows_MONTH,
                      gof = gm,
                      title_words = "Estimation results for suicide rates, without covariates", 
                      output_style = "latex") %>% 
  kableExtra::add_header_above(c(" " = 1, "Total" = 2, "Female" = 2, "Male" = 2)) %>%
  kableExtra::add_footnote(c("Notes: Columns (1), (3), and (5) present baseline WLS estimates shown in  the left-hand side of Figure \\ref{fig:DID_unemploy_on_suicide}. Columns (2), (4), and (6) present WLS estimates based on the model \\eqref{eq:did_model_ver2}, weighted by prefecture population size. The treatment variable is the COVID-19-induced employment shock, which is calculated as equation \\eqref{eq:employment_shock}. Robust standard errors are clustered at the prefecture level."),threeparttable = TRUE, notation = "none",escape = FALSE) %>% 
  kableExtra::column_spec(2:7, width = "1.5cm") %>% 
  kableExtra::save_kable("output/table_unemploy_diff2_on_suicide_robust.tex")
```

# Regression table/回帰結果表 with covar

```{r DID_unemploy_on_suicide_covar}
# 列の選択 column order

# 男女合計、女性、男性、YOYのみ, monthlyhのみ

rows_MONTH <- tribble(~name, ~"(1)", ~"(2)", ~"(3)", ~"(4)", ~"(5)", ~"(6)", 
"Ref. month", "\\footnotesize{Jan.2020}", "\\footnotesize{$\\leq$Jan.2020}",  "\\footnotesize{Jan.2020}", "\\footnotesize{$\\leq$Jan.2020}","\\footnotesize{Jan.2020}", "\\footnotesize{$\\leq$Jan.2020}")

## results list
table_results_MONTH <- list()
table_results_MONTH[["(1)"]] <- results_total_WLS_trend_covar
table_results_MONTH[["(2)"]] <- results_total_WLS_trend_covar_onlypost
table_results_MONTH[["(3)"]] <- results_female_WLS_trend_covar
table_results_MONTH[["(4)"]] <- results_female_WLS_trend_covar_onlypost
table_results_MONTH[["(5)"]] <- results_male_WLS_trend_covar
table_results_MONTH[["(6)"]] <- results_male_WLS_trend_covar_onlypost

## HTML table
estimates_table_MONTH(df = table_results_MONTH,
                      rows = rows_MONTH,
                      title_words = "Suicide",
                      gof = gm,
                      output_style = "html") %>%
    kableExtra::add_header_above(c(" " = 1, "Total" = 2, "Female" = 2, "Male" = 2))

## Latex table
estimates_table_MONTH(df = table_results_MONTH,
                      rows = rows_MONTH,
                      gof = gm,
                      title_words = "Estimation results for suicide rates, with covariates", 
                      output_style = "latex") %>% 
  kableExtra::add_header_above(c(" " = 1, "Total" = 2, "Female" = 2, "Male" = 2)) %>%
  kableExtra::add_footnote(c("Notes:  Columns (1), (3), and (5) present WLS estimates shown in the right-hand side of Figure \\ref{fig:DID_unemploy_on_suicide}. Columns (2), (4), and (6) present WLS estimates based on the model \\eqref{eq:did_model_ver2}, weighted by prefecture population size, and eight covariates are additionally controlled for. The treatment variable is the COVID-19-induced employment shock, which is calculated as equation \\eqref{eq:employment_shock}. Robust standard errors are clustered at the prefecture level."),threeparttable = TRUE, notation = "none",escape = FALSE) %>% 
  kableExtra::column_spec(2:7, width = "1.5cm") %>% 
  kableExtra::save_kable("output/table_unemploy_diff2_on_suicide_robust_covar.tex")
```

